package com.igeek.health.mapper;

import com.igeek.health.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fengqq
 * @since 2024-08-26
 */
public interface MenuMapper extends BaseMapper<Menu> {

    //根据一级菜单的path 查询对应的二级菜单列表
    @Select("select m1.name name1,m1.path path1,m1.icon icon1,m2.name name2,m2.path path2,m2.linkUrl\n" +
            "from menu m1 join menu m2\n" +
            "on m1.id=m2.parentMenuId\n" +
            "where m1.path=#{path}\n" +
            "order by m2.priority")
    public List<Map<String,String>> findByMap(@Param("path") String path);

    //根据管理员id 查询动态的一级菜单
    @Select("select m.* " +
            "from user u,user_role ur,role r,role_menu rm,menu m " +
            "where " +
            "u.id=ur.user_id and ur.role_id=r.id and r.id=rm.role_id and rm.menu_id=m.id " +
            "and u.id=#{userId} and m.level=#{level}")
    public List<Menu> selectMenusByUserId(@Param("userId") Integer userId,@Param("level") Integer level);

}
